package com.vitabuybuy.tv.ui.cart.adapter

import androidx.recyclerview.widget.RecyclerView
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ItemCartGoodsBinding
import com.vitabuybuy.tv.dto.CartGoodsDetailsDto
import com.library.common.base.BindRecycAdapter

class CartGoodsAdapter :
    BindRecycAdapter<ItemCartGoodsBinding, CartGoodsDetailsDto.ItemListBean>() {
    override fun onBindViewHolder(
        mBinding: ItemCartGoodsBinding,
        itemData: CartGoodsDetailsDto.ItemListBean,
        holder: RecyclerView.ViewHolder,
        position: Int
    ) {
        mBinding.itemData = itemData
        mBinding.ivMinus.setOnClickListener {
            if (itemData.quantity == 1 || itemData.quantity == 0) return@setOnClickListener
            onReductClick(itemData.id, position)
        }
        mBinding.ivAdd.setOnClickListener { onAddClick(itemData.id, position) }
        mBinding.ivChoose.setOnClickListener {
            //通知父item
            onItemClickChoose(position)
        }
    }


    lateinit var onReductClick: (cartId: Int, itemPosition: Int) -> Unit
    lateinit var onAddClick: (cartId: Int, itemPosition: Int) -> Unit
    lateinit var onItemClickChoose: (position: Int) -> Unit

    override fun normalViewId(viewType: Int): Int {
        return R.layout.item_cart_goods
    }
}
